package com.magnusart.scrumppm.model;

public class Task implements Comparable<Task>
{

	private final int id;
	private final String description;
	private final boolean isDone;
	private final int order;
	
	public Task( TaskBuilder builder ) {
		if( builder.checkStatus() ) {
			id = builder.getID();
			description = builder.getDescription();
			isDone = builder.isDone();
			order = builder.getOrder();
		} else {
			throw new IllegalStateException("Builder is in an illegal state.");
		}
	}
	
	public int getID() {
		return id;
	}

	public String getDescription() {
		return description;
	}

	public boolean isDone() {
		return isDone;
	}
	
	public int getOrder() {
		return order;
	}

	@Override
	public boolean equals( Object o ) {
		if( o == this )
			return true;
		if( !( o instanceof Task ) )
			return false;
		
		Task task = (Task) o;
		return task.id == id;
	}
	@Override
	public int hashCode() {
		// StoryID is unique in the database, no two duplicates are allowed.
		int result = 19;
		result += 61 + id;
		return result;
	}
	@Override
	public String toString() {
		return "[ TASK ID: " + id 
				+ ", Description: " + description
				+ ", Done: " + isDone 
				+ ", Order: " + order
				+ " ]";
	}
	
	@Override
	public int compareTo( Task task ) {
		// If Task ID are the same the task
		// objects are equal, since the id
		// field is unique in the database. 
		// No two duplicates are allowed.
		return id - task.id;
	}


}
